#include <QApplication>
#include <QTableView>
#include <QStandardItemModel>
#include <QListView>
#include <QTreeView>
#include <QTableView>
#include <QWidget>
int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

    QWidget *ListViewWidget=new QWidget;
    QWidget *TreeViewWidget=new QWidget;
    QWidget *TableViewWidget=new QWidget;

    ListViewWidget->resize(400,400);
    TreeViewWidget->resize(400,400);
    TableViewWidget->resize(400,400);

    //三种视图
    QListView *listview = new QListView(ListViewWidget);
    QTreeView *treeview = new QTreeView(TreeViewWidget);
    QTableView *tableview = new QTableView(TableViewWidget);

    //三种模型
    QStandardItemModel *List_Model = new QStandardItemModel;
    QStandardItemModel *Tree_Model = new QStandardItemModel;
    QStandardItemModel *Table_Model = new QStandardItemModel(3,3);

    //添加数据
    //列表

    for(int row=1;row<=10;row++)
    {
        List_Model->appendRow(new QStandardItem(QString("这是列表的第%1行").arg(row)));
    }
    listview->setModel(List_Model);

    //树
    Tree_Model->setHorizontalHeaderLabels({"类别", "详情"});    //树形表头
    QStandardItem *root = Tree_Model->invisibleRootItem();//设置根节点
    QStandardItem *parent = new QStandardItem("父节点");
    QStandardItem *son = new QStandardItem("子节点");
    QStandardItem *grandson = new QStandardItem("孙节点");

    //相互嵌套
    root->appendRow(parent);
    parent->appendRow(son);
    son->appendRow(grandson);
    treeview->setModel(Tree_Model);

    //表格
    // 设置表头
    Table_Model->setHorizontalHeaderLabels({"姓名", "年龄", "职业"});
    for(int row=0; row<3; ++row)
    {
        for( int col=0; col<3; ++col)
        {
            QStandardItem *item= new QStandardItem(QString("行%1，列%2").arg(row).arg(col));
            Table_Model->setItem(row,col,item);
        }
    }
    tableview->setModel(Table_Model);

    ListViewWidget->setWindowTitle("这是列表窗口");
    TreeViewWidget->setWindowTitle("这是树形窗口");
    TableViewWidget->setWindowTitle("这是表格窗口");

    ListViewWidget->move(0,0);
    TreeViewWidget->move(645,0);
    TableViewWidget->move(1285,0);

    ListViewWidget->show();
    TreeViewWidget->show();
    TableViewWidget->show();


    return app.exec();
}
